home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / t3dlib_src_r43.lha / write.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  26.1 KB  |  953 lines

  1. /* write.c - dump the internal database to a TTDDD FILE
  2.  *         - written by Glenn M. Lewis - 7/19/91
  3.  *         - Altered for Imagine 3.0 support - Rob Hounsell - Sept.94
  4.  */
  5.  
  6. static char rcs_id[] = "$Id: write.c,v 1.24 1995/02/01 22:21:43 glewis Exp glewis $";
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. #include "t3dlib.h"
  11. #ifdef __STDC__
  12. #include <stdlib.h>
  13. #include <strings.h>
  14. #include "write_protos.h"
  15. #endif
  16.  
  17. static void process_DESC();
  18. static void process_EXTR();
  19. static void process_INFO();
  20. static void process_OBJ();
  21. static void process_ISTG();
  22.  
  23. /* Two-space tabs */
  24. #define TABSTOP "  "
  25.  
  26. static FILE *out;
  27. static char tab[133], strin[133];
  28. static int num_OBJ, num_DESC, num_TOBJ;
  29. static int cur_level, cur_objnum;
  30. static int prntline;
  31.  
  32. static struct save_hier {
  33.     int objnum;
  34.     struct save_hier *next;
  35. } *root = 0;
  36. typedef struct save_hier HIER;
  37.  
  38. /* Here are a few necessary utilities */
  39.  
  40. static void indent()
  41. {
  42.     strcat(tab, TABSTOP);
  43. }
  44.  
  45. static void outdent()
  46. {
  47.     register int i = strlen(tab) - strlen(TABSTOP);
  48.     if (i<0) {
  49.         fprintf(stderr, "Whoa, Glenn!  You blew it!\n");
  50.         tab[0] = '\0';
  51.         return;
  52.     }
  53.     tab[i] = '\0';
  54. }
  55.  
  56. #define ROUNDIT(x) ((double)((long)((x)*1000.0+0.5-((x)<0.0)))/1000.0)
  57.  
  58. static void send_XYZ(f)            /* Print a common string */
  59. XYZ_st *f;
  60. {
  61.     fprintf(out, " X=%.12g",   ROUNDIT(f->x));
  62.     fprintf(out, " Y=%.12g",   ROUNDIT(f->y));
  63.     fprintf(out, " Z=%.12g\n", ROUNDIT(f->z));
  64. }
  65.  
  66. static void stage_RGB(rgb)            /* Print a common string */
  67. XYZ_st *rgb;
  68. {
  69.     fprintf(out, " R=%.12g",   ROUNDIT(rgb->x));
  70.     fprintf(out, " G=%.12g",   ROUNDIT(rgb->y));
  71.     fprintf(out, " B=%.12g ",  ROUNDIT(rgb->z));
  72. }
  73.  
  74. static void send_RGB(rgb)            /* Print a common string */
  75. RGB_st *rgb;
  76. {
  77.     fprintf(out, " R=%u",   rgb->r);
  78.     fprintf(out, " G=%u",   rgb->g);
  79.     fprintf(out, " B=%u\n", rgb->b);
  80. }
  81.  
  82. /********************/
  83. /* The MAIN section */
  84. /********************/
  85.  
  86. int write_TTDDD(world, file)
  87. WORLD *world;
  88. FILE *file;
  89. {
  90.     register OBJECT *o;
  91.  
  92.     if (!(out=file) || !world) return(0);    /* File not open */
  93.  
  94.     tab[0] = '\0';
  95.     num_OBJ = num_DESC = num_TOBJ = 0;
  96.  
  97.     fprintf(out, "%% T3DLIB %s - Written by Glenn M. Lewis - 940217\n\n",
  98.         REV);
  99.     if (world->info) process_INFO(world->info);
  100.     if (world->istg) process_ISTG(world->istg);
  101.     for (o=world->object; o; o=o->next)
  102.         process_OBJ(o);
  103.     return(1);
  104. }
  105.  
  106. static void process_INFO(info)
  107. INFO *info;
  108. {
  109.     register int i;
  110.  
  111.     fprintf(out, "%sINFO Begin\n", tab);
  112.     indent();
  113.     for (i=0; i<8; i++)
  114.         if (info->brsh[i][0])
  115.             fprintf(out, "%sBRSH[%d]=\"%s\"\n", tab, i, info->brsh[i]);
  116.  
  117.     for (i=0; i<8; i++)
  118.         if (info->stnc[i][0])
  119.             fprintf(out, "%sSTNC[%d]=\"%s\"\n", tab, i, info->stnc[i]);
  120.  
  121.     for (i=0; i<8; i++)
  122.         if (info->txtr[i][0])
  123.             fprintf(out, "%sTXTR[%d]=\"%s\"\n", tab, i, info->txtr[i]);
  124.  
  125.     if (info->obsv) {
  126.         fprintf(out, "%sOBSV Camera", tab); send_XYZ(&info->obsv->came);
  127.         fprintf(out, "%sOBSV Rotate", tab); send_XYZ(&info->obsv->rota);
  128.         fprintf(out, "%sOBSV Focal  %.12g\n", tab, info->obsv->foca);
  129.     }
  130.  
  131.     if (info->otrk[0]) fprintf(out, "%sOTRK \"%s\"\n", tab, info->otrk);
  132.  
  133.     if (info->ostr) {
  134.         if (info->ostr->path[0])
  135.             fprintf(out, "%sOSTR Path \"%s\"\n", tab, info->ostr->path);
  136.         fprintf(out, "%sOSTR Translate", tab); send_XYZ(&info->ostr->tran);
  137.         fprintf(out, "%sOSTR Rotate   ", tab); send_XYZ(&info->ostr->rota);
  138.         fprintf(out, "%sOSTR Scale    ", tab); send_XYZ(&info->ostr->scal);
  139.         i = info->ostr->info;
  140.         strin[0] = '\0';
  141.         if (i&(1<<0))  strcat(strin, " ABS_TRA");
  142.         if (i&(1<<1))  strcat(strin, " ABS_ROT");
  143.         if (i&(1<<2))  strcat(strin, " ABS_SCL");
  144.         if (i&(1<<4))  strcat(strin, " LOC_TRA");
  145.         if (i&(1<<5))  strcat(strin, " LOC_ROT");
  146.         if (i&(1<<6))  strcat(strin, " LOC_SCL");
  147.         if (i&(1<<8))  strcat(strin, " X_ALIGN");
  148.         if (i&(1<<9))  strcat(strin, " Y_ALIGN");
  149.         if (i&(1<<10)) strcat(strin, " Z_ALIGN");
  150.         if (i&(1<<12)) strcat(strin, " FOLLOW_ME");
  151.         fprintf(out, "%sOSTR Info%s\n", tab, strin);
  152.     }
  153.  
  154.     if (info->fade) {
  155.         fprintf(out, "%sFADE FadeAt %.12g\n", tab, info->fade->at);
  156.         fprintf(out, "%sFADE FadeBy %.12g\n", tab, info->fade->by);
  157.         fprintf(out, "%sFADE FadeTo", tab); send_RGB(&info->fade->to);
  158.     }
  159.  
  160.     if (info->skyc) {
  161.         fprintf(out, "%sSKYC Horizon", tab); send_RGB(&info->skyc->hori);
  162.         fprintf(out, "%sSKYC Zenith ", tab); send_RGB(&info->skyc->zeni);
  163.     }
  164.  
  165.     if (info->ambi)
  166.         { fprintf(out, "%sAMBI", tab); send_RGB(info->ambi); }
  167.  
  168.     if (info->glb0)
  169.         for (i=0; i<8; i++)
  170.             fprintf(out, "%sGLB0[%d]=%u\n", tab, i, info->glb0[i]);
  171.  
  172.     outdent();
  173.     fprintf(out, "%sEnd INFO\n", tab);
  174. }
  175.  
  176. static void process_OBJ(obj)
  177. register OBJECT *obj;
  178. {
  179.     register HIER *p;
  180.     num_OBJ++;
  181.     fprintf(out, "%sOBJ Begin \"Hierarchy %d\"\n", tab, num_OBJ);
  182.     num_DESC = num_TOBJ = 0;        /* Reset counters */
  183.     cur_level = 0;
  184.     cur_objnum = 1;
  185.     prntline = 1;
  186.  
  187.     if (obj->extr) process_EXTR(obj->extr);
  188.     else process_DESC(obj);
  189.  
  190.     while (root) {                /* This should happen at most once. */
  191.         p = root->next;
  192.         free((char *)root);        /* Delete this from list */
  193.         root = p;
  194.         outdent();
  195.     }
  196.  
  197.     fprintf(out, "%sEnd OBJ   \"Hierarchy %d\"\n", tab, num_OBJ);
  198. }
  199.  
  200. static void process_TOBJ()
  201. {
  202.     register HIER *p;
  203.     if (num_DESC-num_TOBJ < cur_level) {    /* Pop old level off HIER */
  204.         cur_level--;
  205.         cur_objnum = root->objnum;
  206.         p = root->next;
  207.         free((char *)root);    /* Delete from list */
  208.         root = p;
  209.         outdent();    /* Pretty file formatting */
  210.     }
  211.     fprintf(out, "%sTOBJ       \"Object %d at level %d of hierarchy %d\"\n",
  212.         tab, cur_objnum-1, num_DESC-num_TOBJ, num_OBJ);
  213.     num_TOBJ++;
  214.     prntline = 1;
  215. }
  216.  
  217. static void process_EXTR(extr)
  218. EXTR *extr;
  219. {
  220.     if (!prntline) fprintf(out, "\n");    /* Print one anyway */
  221.     indent();
  222.     num_DESC++;
  223.  
  224.     fprintf(out, "%sEXTR Begin \"Object %d at level %d of hierarchy %d\"\n",
  225.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  226.     indent();
  227.     fprintf(out, "%sMTRX Translate", tab); send_XYZ(&extr->mtrx.tran);
  228.     fprintf(out, "%sMTRX Scale    ", tab); send_XYZ(&extr->mtrx.scal);
  229.     fprintf(out, "%sMTRX Rotate", tab);
  230.     fprintf(out, " %.12g %.12g %.12g",
  231.         extr->mtrx.rota1.x,
  232.         extr->mtrx.rota1.y,
  233.         extr->mtrx.rota1.z);
  234.     fprintf(out, " %.12g %.12g %.12g",
  235.         extr->mtrx.rota2.x,
  236.         extr->mtrx.rota2.y,
  237.         extr->mtrx.rota2.z);
  238.     fprintf(out, " %.12g %.12g %.12g",
  239.         extr->mtrx.rota3.x,
  240.         extr->mtrx.rota3.y,
  241.         extr->mtrx.rota3.z);
  242.     fprintf(out, "\n");
  243.  
  244.     fprintf(out, "%sLOAD \"%s\"\n", tab, extr->filename);
  245.     outdent();
  246.     fprintf(out, "%sEnd EXTR   \"Object %d at level %d of hierarchy %d\"\n",
  247.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  248.  
  249.     num_TOBJ++;
  250.     cur_objnum++;
  251.     outdent();
  252.     prntline = 1;
  253. }
  254.  
  255. static void process_DESC(object)
  256. OBJECT *object;
  257. {
  258.     register int i, j;
  259.     register HIER *p;
  260.     register OBJECT *obj;
  261.     register DESC *desc = object->desc;
  262.     FGRP *fgrp;
  263.  
  264.     num_DESC++;
  265.     if (num_DESC-num_TOBJ > cur_level) {    /* Push new level in HIER */
  266.         if (!prntline) fprintf(out, "\n");    /* Print one anyway */
  267.         if (!(p = (HIER*)malloc(sizeof(HIER)))) {
  268.             fprintf(stderr, "ERROR!  Out of memory.\n*** ABORT ***\n");
  269.             exit(20);
  270.         }
  271.         p->next = root;        /* Insert into list */
  272.         root = p;
  273.         root->objnum = cur_objnum;
  274.         cur_level++;
  275.         cur_objnum = 1;
  276.         indent();    /* Pretty file formatting */
  277.     }
  278.  
  279.     fprintf(out, "%sDESC Begin \"Object %d at level %d of hierarchy %d\"\n",
  280.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  281.     indent();
  282.  
  283.     if (desc->name[0]) fprintf(out, "%sNAME \"%s\"\n", tab, desc->name);
  284.  
  285.     if (desc->shap) {
  286.         fprintf(out, "%sSHAP Shape = %u\n", tab, desc->shap[0]);
  287.         fprintf(out, "%sSHAP Lamp  = %u\n", tab, desc->shap[1]);
  288.     }
  289.  
  290.     if (desc->posi)
  291.         { fprintf(out, "%sPOSI", tab); send_XYZ(desc->posi); }
  292.  
  293.     if (desc->axis) {
  294.         fprintf(out, "%sAXIS XAxis", tab); send_XYZ(&desc->axis->xaxi);
  295.         fprintf(out, "%sAXIS YAxis", tab); send_XYZ(&desc->axis->yaxi);
  296.         fprintf(out, "%sAXIS ZAxis", tab); send_XYZ(&desc->axis->zaxi);
  297.     }
  298.  
  299.     if (desc->size)
  300.         { fprintf(out, "%sSIZE", tab); send_XYZ(desc->size); }
  301.  
  302.     if (desc->pcount) {
  303.         fprintf(out, "%sPNTS PCount %u\n", tab, desc->pcount);
  304.         for (i=0; i<desc->pcount; i++) {
  305.             fprintf(out, "%sPNTS Point[%d]", tab, i);
  306.             send_XYZ(&desc->pnts[i]);
  307.         }
  308.     }
  309.  
  310.     if (desc->ecount) {
  311.         fprintf(out, "%sEDGE ECount %u\n", tab, desc->ecount);
  312.         for (i=0; i<desc->ecount; i++) {
  313.             fprintf(out, "%sEDGE Edge[%d] %u %u\n", tab, i,
  314.                 desc->edge[i<<1], desc->edge[(i<<1)+1]);
  315.         }
  316.     }
  317.  
  318.     if (desc->eflg) {
  319.         fprintf(out, "%sEFLG Count %u\n", tab, desc->eflg->num);
  320.         for (i=0; i<desc->eflg->num; i++) {
  321.             fprintf(out, "%sEFLG Eflg[%d]=%u\n", tab, i, desc->eflg->eflg[i]);
  322.         }
  323.     }
  324.  
  325.     if (desc->fcount) {
  326.         fprintf(out, "%sFACE TCount %u\n", tab, desc->fcount);
  327.         for (i=0; i<desc->fcount; i++) {
  328.             fprintf(out, "%sFACE Connect[%u] %u %u %u\n", tab, i,
  329.                 desc->face[i*3], desc->face[i*3+1], desc->face[i*3+2]);
  330.         }
  331.     }
  332.  
  333.     for (fgrp=desc->fgrp; fgrp; fgrp=fgrp->next) {
  334.         fprintf(out, "%sFGRP Name \"%s\"\n", tab, fgrp->name);
  335.         fprintf(out, "%sFGRP Count %u\n", tab, fgrp->num);
  336.         for (i=0; i<fgrp->num; i++)
  337.             fprintf(out, "%sFGRP Face[%u]=%u\n", tab, i, fgrp->face[i]);
  338.     }
  339.  
  340.     for (i=0; i<4; i++) {
  341.         if (!desc->txt2[i]) continue;
  342.         fprintf(out, "%sTXT2[%u] Flags %u\n", tab, i, desc->txt2[i]->Flags);
  343.         fprintf(out, "%sTXT2[%u] Translate",tab, i);
  344.         send_XYZ(&desc->txt2[i]->TAxis.tran);
  345.         fprintf(out, "%sTXT2[%u] XAxis",tab, i);
  346.         send_XYZ(&desc->txt2[i]->TAxis.rota1);
  347.         fprintf(out, "%sTXT2[%u] YAxis",tab, i);
  348.         send_XYZ(&desc->txt2[i]->TAxis.rota2);
  349.         fprintf(out, "%sTXT2[%u] ZAxis",tab, i);
  350.         send_XYZ(&desc->txt2[i]->TAxis.rota3);
  351.         fprintf(out, "%sTXT2[%u] Scale",tab, i);
  352.         send_XYZ(&desc->txt2[i]->TAxis.scal);
  353.         for (j = 0; j < 16; j++) {
  354.             fprintf(out, "%sTXT2[%u] Params[%u]=%.12g\n", tab, i, j, 
  355.             desc->txt2[i]->Params[j]);
  356.         }
  357.         for (j = 0; j < 16; j++) {
  358.             fprintf(out, "%sTXT2[%u] PFlags[%u]=%u\n", tab, i, j, 
  359.             desc->txt2[i]->PFlags[j]);
  360.         }
  361.         fprintf(out, "%sTXT2[%u] SubGroup \"%s\"\n", tab, i, 
  362.             desc->txt2[i]->SubName);
  363.         fprintf(out, "%sTXT2[%u] Texture \"%s\"\n",tab, i, 
  364.             desc->txt2[i]->Name);
  365.     }
  366.  
  367.     if (desc->colr) { fprintf(out, "%sCOLR", tab); send_RGB(desc->colr); }
  368.  
  369.     if (desc->refl) { fprintf(out, "%sREFL", tab); send_RGB(desc->refl); }
  370.  
  371.     if (desc->tran) { fprintf(out, "%sTRAN", tab); send_RGB(desc->tran); }
  372.  
  373.     if (desc->spc1) { fprintf(out, "%sSPC1", tab); send_RGB(desc->spc1); }
  374.  
  375.     if (desc->fcount) {
  376.         fprintf(out, "%sCLST Count %u\n", tab, desc->fcount);
  377.         for (i=0; i<desc->fcount; i++) {
  378. #if 0
  379. /* Never skip printing a CLST value - GML - 3/27/92 */
  380.             if (desc->colr) {
  381.                 if (desc->clst[i*3  ]==desc->colr->r &&
  382.                     desc->clst[i*3+1]==desc->colr->g &&
  383.                     desc->clst[i*3+2]==desc->colr->b) continue; /* Skip */
  384.             } else {
  385.                 if (desc->clst[i*3  ]==240 &&
  386.                     desc->clst[i*3+1]==240 &&
  387.                     desc->clst[i*3+2]==240) continue;    /* Skip this one */
  388.             }
  389. #endif
  390.             fprintf(out, "%sCLST Color[%u]", tab, i);
  391.             send_RGB((RGB_st*)&desc->clst[i*3]);
  392.         }
  393.         fprintf(out, "%sRLST Count %u\n", tab, desc->fcount);
  394.         for (i=0; i<desc->fcount; i++) {
  395.             if (desc->refl) {
  396.                 if (desc->rlst[i*3  ]==desc->refl->r &&
  397.                     desc->rlst[i*3+1]==desc->refl->g &&
  398.                     desc->rlst[i*3+2]==desc->refl->b) continue; /* Skip */
  399.             } else {
  400.                 if (desc->rlst[i*3  ]==0 &&
  401.                     desc->rlst[i*3+1]==0 &&
  402.                     desc->rlst[i*3+2]==0) continue;    /* Skip this one */
  403.             }
  404.             fprintf(out, "%sRLST Color[%u]", tab, i);
  405.             send_RGB((RGB_st*)&desc->rlst[i*3]);
  406.         }
  407.         fprintf(out, "%sTLST Count %u\n", tab, desc->fcount);
  408.         for (i=0; i<desc->fcount; i++) {
  409.             if (desc->tran) {
  410.                 if (desc->tlst[i*3  ]==desc->tran->r &&
  411.                     desc->tlst[i*3+1]==desc->tran->g &&
  412.                     desc->tlst[i*3+2]==desc->tran->b) continue; /* Skip */
  413.             } else {
  414.                 if (desc->tlst[i*3  ]==0 &&
  415.                     desc->tlst[i*3+1]==0 &&
  416.                     desc->tlst[i*3+2]==0) continue;    /* Skip this one */
  417.             }
  418.             fprintf(out, "%sTLST Color[%u]", tab, i);
  419.             send_RGB((RGB_st*)&desc->tlst[i*3]);
  420.         }
  421.     }
  422.  
  423.     if (desc->tpar) {
  424.         for (i=0; i<16; i++)
  425.             fprintf(out, "%sTPAR[%u]=%.12g\n", tab, i, desc->tpar[i]);
  426.     }
  427.  
  428.     if (desc->surf) {
  429.         for (i=0; i<5; i++)
  430.             fprintf(out, "%sSURF[%u]=%d\n", tab, i, desc->surf[i]);
  431.     }
  432.  
  433.     if (desc->mttr) {
  434.         fprintf(out, "%sMTTR Type =%u\n", tab, desc->mttr->type);
  435.         fprintf(out, "%sMTTR Index=%.12g\n", tab, (double)desc->mttr->indx);
  436.     }
  437.  
  438.     if (desc->spec) {
  439.         fprintf(out, "%sSPEC Spec=%u\n", tab, desc->spec[0]);
  440.         fprintf(out, "%sSPEC Hard=%u\n", tab, desc->spec[1]);
  441.     }
  442.  
  443.     if (desc->prp0) {
  444.         for (i=0; i<6; i++)
  445.             fprintf(out, "%sPRP0[%u]=%u\n", tab, i, desc->prp0[i]);
  446.     }
  447.  
  448.     if (desc->prp1) {
  449.         for (i=0; i<8; i++)
  450.             fprintf(out, "%sPRP1[%u]=%u\n", tab, i, desc->prp1[i]);
  451.     }
  452.  
  453.     if (desc->ints)
  454.         fprintf(out, "%sINTS=%.12g\n", tab, desc->ints);
  455.  
  456.     if (desc->int1) { fprintf(out, "%sINT1", tab); send_XYZ(desc->int1); }
  457.  
  458.     if (desc->stry) {
  459.         fprintf(out, "%sSTRY Path \"%s\"\n", tab, desc->stry->path);
  460.         fprintf(out, "%sSTRY Translate", tab); send_XYZ(&desc->stry->tran);
  461.         fprintf(out, "%sSTRY Rotate   ", tab); send_XYZ(&desc->stry->rota);
  462.         fprintf(out, "%sSTRY Scale    ", tab); send_XYZ(&desc->stry->scal);
  463.         i = desc->stry->info;
  464.         strin[0] = '\0';
  465.         if (i&(1<<0))  strcat(strin, " ABS_TRA");
  466.         if (i&(1<<1))  strcat(strin, " ABS_ROT");
  467.         if (i&(1<<2))  strcat(strin, " ABS_SCL");
  468.         if (i&(1<<4))  strcat(strin, " LOC_TRA");
  469.         if (i&(1<<5))  strcat(strin, " LOC_ROT");
  470.         if (i&(1<<6))  strcat(strin, " LOC_SCL");
  471.         if (i&(1<<8))  strcat(strin, " X_ALIGN");
  472.         if (i&(1<<9))  strcat(strin, " Y_ALIGN");
  473.         if (i&(1<<10)) strcat(strin, " Z_ALIGN");
  474.         if (i&(1<<12)) strcat(strin, " FOLLOW_ME");
  475.         fprintf(out, "%sSTRY Info%s\n", tab, strin);
  476.     }
  477.  
  478.     outdent();
  479.     fprintf(out, "%sEnd DESC   \"Object %d at level %d of hierarchy %d\"\n",
  480.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  481.  
  482.     for (obj=object->child; obj; obj=obj->next) {
  483.         if (obj->extr) process_EXTR(obj->extr);
  484.         else process_DESC(obj);
  485.     }
  486.  
  487.     cur_objnum++;
  488.     prntline = 0;
  489.     process_TOBJ();
  490. }
  491.  
  492. /************************************************************************/
  493. /* New code to write staging file - written by Glenn M. Lewis - 8/11/92 */
  494. /* Added Imagine3 support - Rob Hounsell - Sept 94                      */
  495. /************************************************************************/
  496.  
  497. static void process_OSZ2();
  498. static void process_OSIZ();
  499. static void process_POS2();
  500. static void process_POSN();
  501. static void process_ALN2();
  502. static void process_ALGN();
  503. static void process_ASSC();
  504. static void process_HING();
  505. static void process_LYR0();
  506. static void process_GLB3();
  507. static void process_GLB2();
  508. static void process_AXIS();
  509. static void process_LIT2();
  510. static void process_LITE();
  511. static void process_FIL3();
  512. static void process_FILE();
  513. static void process_SPFX();
  514.  
  515. static void process_ISTG(istg)
  516. register ISTG *istg;
  517. {
  518.     register SOBJ *sobj;
  519.  
  520.     fprintf(out, "\n%sISTG Begin\n", tab);
  521.  
  522.     indent();
  523.  
  524.     fprintf(out, "\n%sMAXF %u\t%% Max. frames\n", tab, istg->maxf);
  525.  
  526.     fprintf(out, "%sLOOP %u\t%% Loop flag \n", tab, istg->loop);
  527.  
  528.     /* Sort the SOBJ's first? */
  529.  
  530. /* Here is the main loop: */
  531.     for (sobj=istg->head; sobj; sobj=sobj->next) {
  532.         fprintf(out, "\n%sSOBJ Begin\n", tab);
  533.         indent();
  534.  
  535.         fprintf(out, "\n%sNAME \"%s\"\n", tab, sobj->name);
  536.         fprintf(out, "%sSTGF %u\n", tab, sobj->stgf);
  537.         if (sobj->lyr0) process_LYR0(sobj);
  538.         if (sobj->glb3) process_GLB3(sobj);
  539.         if (sobj->glb2) process_GLB2(sobj);
  540.         if (sobj->fil3) process_FIL3(sobj);
  541.         if (sobj->file) process_FILE(sobj);
  542.         if (sobj->lit2) process_LIT2(sobj);
  543.         if (sobj->lite) process_LITE(sobj);
  544.         if (sobj->axis) process_AXIS(sobj);
  545.         if (sobj->pos2) process_POS2(sobj);
  546.         if (sobj->posn) process_POSN(sobj);
  547.         if (sobj->aln2) process_ALN2(sobj);
  548.         if (sobj->algn) process_ALGN(sobj);
  549.         if (sobj->osz2) process_OSZ2(sobj);
  550.         if (sobj->osiz) process_OSIZ(sobj);
  551.         if (sobj->assc) process_ASSC(sobj);
  552.         if (sobj->hing) process_HING(sobj);
  553.         if (sobj->spfx) process_SPFX(sobj->spfx, 0);
  554.         if (sobj->s2fx) process_SPFX(sobj->s2fx, 2);
  555.         if (sobj->s3fx) process_SPFX(sobj->s3fx, 3);
  556.         if (sobj->s4fx) process_SPFX(sobj->s4fx, 4);
  557.  
  558.         outdent();
  559.         fprintf(out, "\n%sEND SOBJ\n", tab);
  560.     }
  561.  
  562. /* All done. */
  563.     outdent();
  564.     fprintf(out, "\nEND ISTG\n\n");
  565. }
  566.  
  567. /* Chunks unique to Imagine 2.0 */
  568. static void process_OSIZ(sobj)
  569. SOBJ *sobj;
  570. {
  571.     register OSIZ *osiz;
  572.  
  573.     fputs("\n", out);
  574.     for (osiz=sobj->osiz; osiz; osiz=osiz->next) {
  575.         fprintf(out, "%sOSIZ FLAGS=%u ", tab, osiz->flags);
  576.         fprintf(out, "START=%u ", osiz->start);
  577.         fprintf(out, "STOP=%u SIZE", osiz->stop);
  578.         send_XYZ(&osiz->size);
  579.     }
  580. }
  581.  
  582. static void process_POSN(sobj)
  583. SOBJ *sobj;
  584. {
  585.     register POSN *posn;
  586.   register PTH2 *pth2;
  587.  
  588.     fputs("\n", out);
  589.     for (posn=sobj->posn; posn; posn=posn->next) {
  590.     if (posn->chunk_type == POSN_CHUNK) {
  591.            fprintf(out, "%sPOSN FLAGS %u ", tab, posn->flags);
  592.            fprintf(out, "START=%u ", posn->start);
  593.            fprintf(out, "STOP=%u POSN", posn->stop);
  594.            send_XYZ(&posn->posn);
  595.         }
  596.         else if (posn->chunk_type == PTH2_CHUNK) {
  597.            pth2 = posn;
  598.            fprintf(out, "%sPTH2 FLAGS=%u ", tab, pth2->flags);
  599.            fprintf(out, "START=%u ", pth2->start);
  600.            fprintf(out, "STOP=%u ", pth2->stop);
  601.            fprintf(out, "ACCEL=%lu ", pth2->acceleration_frames);
  602.            fprintf(out, "START_SPEED=%.12g ", pth2->start_speed);
  603.            fprintf(out, "DECEL=%lu ", pth2->deacceleration_frames);
  604.            fprintf(out, "END_SPEED=%.12g ", pth2->end_speed);
  605.            fprintf(out, "PATH=\"%s\"\n", pth2->path);
  606.         }
  607.         else {
  608.             fprintf(stderr, "Unknown chunk type %d in POSN chain.\n",
  609.             posn->chunk_type);
  610.         }
  611.     }
  612. }
  613.  
  614. static void process_ALGN(sobj)
  615. SOBJ *sobj;
  616. {
  617.     register ALGN *algn;
  618.     register PALN *paln;
  619.     register TALN *taln;
  620.  
  621.     fputs("\n", out);
  622.     for (algn=sobj->algn; algn; algn=algn->next) {
  623.         if (algn->chunk_type == ALGN_CHUNK) {
  624.             fprintf(out, "%sALGN FLAGS=%u ", tab, algn->flags);
  625.             fprintf(out, "START=%u ", algn->start);
  626.             fprintf(out, "STOP=%u ALGN", algn->stop);
  627.             send_XYZ(&algn->algn);
  628.         }
  629.         else if (algn->chunk_type == PALN_CHUNK) {
  630.            paln = algn;
  631.             fprintf(out, "%sPALN FLAGS %u ", tab, paln->flags);
  632.             fprintf(out, "START=%u ", paln->start);
  633.             fprintf(out, "STOP=%u\n", paln->stop);
  634.       }
  635.         else if (algn->chunk_type == TALN_CHUNK) {
  636.           taln = algn;
  637.             fprintf(out, "%sTALN FLAGS=%u ", tab, taln->flags);
  638.             fprintf(out, "START=%u ", taln->start);
  639.             fprintf(out, "STOP=%u ", taln->stop);
  640.             fprintf(out, "INITIAL_Y=%.12g ", taln->initial_y);
  641.             fprintf(out, "FINAL_Y=%.12g ", taln->final_y);
  642.             fprintf(out, "NAME=\"%s\"\n", taln->trackobj);
  643.       }
  644.         else {
  645.             fprintf(stderr, "Unknown chunk type %d in ALGN chain.\n",
  646.             algn->chunk_type);
  647.         }
  648.     }
  649. }
  650.  
  651. static void process_HING(sobj)
  652. SOBJ *sobj;
  653. {
  654.     register HING *hing;
  655.  
  656.     fputs("\n", out);
  657.     for (hing=sobj->hing; hing; hing=hing->next) {
  658.         fprintf(out, "%sHING FLAGS=%u ", tab, hing->flags);
  659.         fprintf(out, "START=%u ", hing->start);
  660.         fprintf(out, "STOP=%u ", hing->stop);
  661.         fprintf(out, "NAME=\"%s\"\n", hing->hingeobj);
  662.     }
  663. }
  664.  
  665. static void process_GLB2(sobj)
  666. SOBJ *sobj;
  667. {
  668.     register GLB2 *glb2;
  669.  
  670.     fputs("\n", out);
  671.     for (glb2=sobj->glb2; glb2; glb2=glb2->next) {
  672.         fprintf(out, "%sGLB2 FLAGS=%u ", tab, glb2->flags);
  673.         fprintf(out, "START=%u ", glb2->start);
  674.         fprintf(out, "STOP=%u ", glb2->stop);
  675.         fprintf(out, "SKY_BLEND=%lu ", glb2->sky_blending);
  676.         fprintf(out, "STARFIELD=%.12g ", glb2->starfield);
  677.         fprintf(out, "TRANSITION=%lu ", glb2->transition);
  678.         fprintf(out, "AMBIENT ");
  679.         stage_RGB(&glb2->ambient);
  680.         fprintf(out, "HORIZON ");
  681.         stage_RGB(&glb2->horizon);
  682.         fprintf(out, "ZENITH1 ");
  683.         stage_RGB(&glb2->zenith1);
  684.         fprintf(out, "ZENITH2 ");
  685.         stage_RGB(&glb2->zenith2);
  686.         fprintf(out, "FOG_COL ");
  687.         stage_RGB(&glb2->fog_color);
  688.         fprintf(out, "FOG_BOTTOM=%.12g ", glb2->fog_bottom);
  689.         fprintf(out, "FOG_TOP=%.12g ", glb2->fog_top);
  690.         fprintf(out, "FOG_LENGTH=%.12g ", glb2->fog_length);
  691.         fprintf(out, "BRUSH_SEQ=%lu ", glb2->brush_seq);
  692.         fprintf(out, "BACKDROP_SEQ=%lu ", glb2->backdrop_seq);
  693.         fprintf(out, "BACKDROP=\"%s\" ", glb2->backdrop);
  694.         fprintf(out, "GLOBALBRUSH=\"%s\"\n", glb2->globalbrush);
  695.     }
  696. }
  697.  
  698. static void process_LITE(sobj)
  699. SOBJ *sobj;
  700. {
  701.     register LITE *lite;
  702.  
  703.     fputs("\n", out);
  704.     for (lite=sobj->lite; lite; lite=lite->next) {
  705.         fprintf(out, "%sLITE FLAGS %u ", tab, lite->flags);
  706.         fprintf(out, "START=%u ", lite->start);
  707.         fprintf(out, "STOP=%u ", lite->stop);
  708.         fprintf(out, "COLOR ");
  709.         stage_RGB(&lite->color);
  710.         fprintf(out, "TRANSITION=%lu\n", lite->transition);
  711.     }
  712. }
  713.  
  714. static void process_FILE(sobj)
  715. SOBJ *sobj;
  716. {
  717.     register SFILE *file;
  718.  
  719.     fputs("\n", out);
  720.     for (file=sobj->file; file; file=file->next) {
  721.         fprintf(out, "%sFILE FLAGS=%u ", tab, file->flags);
  722.         fprintf(out, "START=%u ", file->start);
  723.         fprintf(out, "STOP=%u ", file->stop);
  724.         fprintf(out, "CYCLES=%.12g ", file->cycles_to_perform);
  725.         fprintf(out, "INITIAL_PHASE=%.12g ", file->initial_cycle_phase);
  726.         fprintf(out, "TRANSITION=%lu ", file->transition);
  727.         fprintf(out, "NAME=\"%s\"\n", file->object_description);
  728.     }
  729. }
  730.  
  731. /* Chunks unique to Imagine 3.0 or common to both */
  732. static void process_OSZ2(sobj)
  733. SOBJ *sobj;
  734. {
  735.     register OSZ2 *osz2;
  736.  
  737.     fputs("\n", out);
  738.     for (osz2=sobj->osz2; osz2; osz2=osz2->next) {
  739.         fprintf(out, "%sOSZ2 FLAGS=%u ", tab, osz2->flags);
  740.         fprintf(out, "START=%u ", osz2->start);
  741.         fprintf(out, "STOP=%u ", osz2->stop);
  742.         fprintf(out, "VEL0=%.12g ", osz2->vel_0);
  743.         fprintf(out, "VEL1=%.12g SIZE", osz2->vel_1);
  744.         send_XYZ(&osz2->size);
  745.     }
  746. }
  747.  
  748. static void process_POS2(sobj)
  749. SOBJ *sobj;
  750. {
  751.     register POS2 *pos2;
  752.   register PTH2 *pth2;
  753.  
  754.     fputs("\n", out);
  755.     for (pos2=sobj->pos2; pos2; pos2=pos2->next) {
  756.     if (pos2->chunk_type == POS2_CHUNK) {
  757.            fprintf(out, "%sPOS2 FLAGS=%u ", tab, pos2->flags);
  758.            fprintf(out, "START=%u ", pos2->start);
  759.            fprintf(out, "STOP=%u ", pos2->stop);
  760.            fprintf(out, "VEL0=%.12g ", pos2->vel_0);
  761.            fprintf(out, "VEL1=%.12g POS2", pos2->vel_1);
  762.            send_XYZ(&pos2->pos2);
  763.         }
  764.         else if (pos2->chunk_type == PTH2_CHUNK) {
  765.            pth2 = pos2;
  766.            fprintf(out, "%sPTH2 FLAGS=%u ", tab, pth2->flags);
  767.            fprintf(out, "START=%u ", pth2->start);
  768.            fprintf(out, "STOP=%u ", pth2->stop);
  769.            fprintf(out, "ACCEL=%lu ", pth2->acceleration_frames);
  770.            fprintf(out, "START_SPEED=%.12g ", pth2->start_speed);
  771.            fprintf(out, "DECEL=%lu ", pth2->deacceleration_frames);
  772.            fprintf(out, "END_SPEED=%.12g ", pth2->end_speed);
  773.            fprintf(out, "PATH=\"%s\"\n", pth2->path);
  774.         }
  775.         else {
  776.             fprintf(stderr, "Unknown chunk type %d in POS2 chain.\n",
  777.             pos2->chunk_type);
  778.         }
  779.     }
  780. }
  781.  
  782. static void process_ALN2(sobj)
  783. SOBJ *sobj;
  784. {
  785.     register ALN2 *aln2;
  786.     register PALN *paln;
  787.     register TALN *taln;
  788.  
  789.     fputs("\n", out);
  790.     for (aln2=sobj->aln2; aln2; aln2=aln2->next) {
  791.         if (aln2->chunk_type == ALN2_CHUNK) {
  792.             fprintf(out, "%sALN2 FLAGS=%u ", tab, aln2->flags);
  793.             fprintf(out, "START=%u ", aln2->start);
  794.             fprintf(out, "STOP=%u ", aln2->stop);
  795.             fprintf(out, "VEL0=%.12g ", aln2->vel_0);
  796.             fprintf(out, "VEL1=%.12g ALN2", aln2->vel_1);
  797.             send_XYZ(&aln2->aln2);
  798.         }
  799.         else if (aln2->chunk_type == PALN_CHUNK) {
  800.            paln = aln2;
  801.             fprintf(out, "%sPALN FLAGS %u ", tab, paln->flags);
  802.             fprintf(out, "START=%u ", paln->start);
  803.             fprintf(out, "STOP=%u\n", paln->stop);
  804.       }
  805.         else if (aln2->chunk_type == TALN_CHUNK) {
  806.           taln = aln2;
  807.             fprintf(out, "%sTALN FLAGS=%u ", tab, taln->flags);
  808.             fprintf(out, "START=%u ", taln->start);
  809.             fprintf(out, "STOP=%u ", taln->stop);
  810.             fprintf(out, "INITIAL_Y=%.12g ", taln->initial_y);
  811.             fprintf(out, "FINAL_Y=%.12g ", taln->final_y);
  812.             fprintf(out, "NAME=\"%s\"\n", taln->trackobj);
  813.       }
  814.         else {
  815.             fprintf(stderr, "Unknown chunk type %d in ALN2 chain.\n",
  816.             aln2->chunk_type);
  817.         }
  818.     }
  819. }
  820.  
  821. static void process_ASSC(sobj)
  822. SOBJ *sobj;
  823. {
  824.     register ASSC *assc;
  825.  
  826.     fputs("\n", out);
  827.     for (assc=sobj->assc; assc; assc=assc->next) {
  828.         fprintf(out, "%sASSC FLAGS=%u ", tab, assc->flags);
  829.         fprintf(out, "START=%u ", assc->start);
  830.         fprintf(out, "STOP=%u ", assc->stop);
  831.         fprintf(out, "NAME=\"%s\"\n", assc->assc_obj);
  832.     }
  833. }
  834.  
  835. static void process_LYR0(sobj)
  836. SOBJ *sobj;
  837. {
  838.     register LYR0 *lyr0;
  839.  
  840.     for (lyr0=sobj->lyr0; lyr0; lyr0=lyr0->next) {
  841.         fprintf(out, "%sLYR0=%u", tab, lyr0->layer);
  842.     }
  843.     fputs("\n", out);
  844. }
  845.  
  846. static void process_GLB3(sobj)
  847. SOBJ *sobj;
  848. {
  849.     register GLB3 *glb3;
  850.  
  851.     fputs("\n", out);
  852.     for (glb3=sobj->glb3; glb3; glb3=glb3->next) {
  853.         fprintf(out, "%sGLB3 FLAGS=%u ", tab, glb3->flags);
  854.         fprintf(out, "START=%u ", glb3->start);
  855.         fprintf(out, "STOP=%u ", glb3->stop);
  856.         fprintf(out, "STARFIELD=%.12g ", glb3->starfield);
  857.         fprintf(out, "TRANSITION=%lu ", glb3->transition);
  858.         fprintf(out, "AMBIENT");
  859.         stage_RGB(&glb3->ambient);
  860.         fprintf(out, " HORIZON");
  861.         stage_RGB(&glb3->horizon);
  862.         fprintf(out, " ZENITH1");
  863.         stage_RGB(&glb3->zenith1);
  864.         fprintf(out, " ZENITH2");
  865.         stage_RGB(&glb3->zenith2);
  866.         fprintf(out, " FOG_COL");
  867.         stage_RGB(&glb3->fog_color);
  868.         fprintf(out, "FOG_BOTTOM=%.12g ", glb3->fog_bottom);
  869.         fprintf(out, "FOG_TOP=%.12g ", glb3->fog_top);
  870.         fprintf(out, "FOG_LENGTH=%.12g ", glb3->fog_length);
  871.         fprintf(out, "BRUSH_SEQ=%lu ", glb3->brush_seq);
  872.         fprintf(out, "BACKDROP_SEQ=%lu ", glb3->backdrop_seq);
  873.         fprintf(out, "BACKDROP=\"%s\" ", glb3->backdrop);
  874.         fprintf(out, "GLOBALBRUSH=\"%s\"\n", glb3->globalbrush);
  875.     }
  876. }
  877.  
  878. static void process_AXIS(sobj)
  879. SOBJ *sobj;
  880. {
  881.     register SAXIS *axis;
  882.  
  883.     fputs("\n", out);
  884.     for (axis=sobj->axis; axis; axis=axis->next) {
  885.         fprintf(out, "%sAXIS FLAGS=%u ", tab, axis->flags);
  886.         fprintf(out, "START=%u ", axis->start);
  887.         fprintf(out, "STOP=%u\n", axis->stop);
  888.     }
  889. }
  890.  
  891. static void process_LIT2(sobj)
  892. SOBJ *sobj;
  893. {
  894.     register LIT2 *lit2;
  895.  
  896.     fputs("\n", out);
  897.     for (lit2=sobj->lit2; lit2; lit2=lit2->next) {
  898.         fprintf(out, "%sLIT2 FLAGS %u ", tab, lit2->flags);
  899.         fprintf(out, "START=%u ", lit2->start);
  900.         fprintf(out, "STOP=%u ", lit2->stop);
  901.         fprintf(out, "COLOR ");
  902.         stage_RGB(&lit2->color);
  903.         fprintf(out, "TRANSITION=%lu\n", lit2->transition);
  904.     }
  905. }
  906.  
  907. static void process_FIL3(sobj)
  908. SOBJ *sobj;
  909. {
  910.     register FIL3 *fil3;
  911.  
  912.     fputs("\n", out);
  913.     for (fil3=sobj->fil3; fil3; fil3=fil3->next) {
  914.         fprintf(out, "%sFIL3 FLAGS=%u ", tab, fil3->flags);
  915.         fprintf(out, "START=%u ", fil3->start);
  916.         fprintf(out, "STOP=%u ", fil3->stop);
  917.         fprintf(out, "CYCLES=%.12g ", fil3->cycles_to_perform);
  918.         fprintf(out, "INITIAL_PHASE=%.12g ", fil3->initial_cycle_phase);
  919.         fprintf(out, "VEL0=%.12g ", fil3->vel_0);
  920.         fprintf(out, "VEL1=%.12g ", fil3->vel_1);
  921.         fprintf(out, "STATE=\"%s\" ", fil3->state);
  922.         fprintf(out, "NAME=\"%s\"\n", fil3->object_description);
  923.     }
  924. }
  925.  
  926. static void process_SPFX (spfx_ptr, index)
  927. SPFX *spfx_ptr;
  928. int index;
  929. {
  930.     register SPFX *spfx;
  931.  
  932.     fputs("\n", out);
  933.     for (spfx=spfx_ptr; spfx; spfx=spfx->next) {
  934.         switch (index) {
  935.             case 0:
  936.                 fprintf(out, "%sSPFX FLAGS=%u ", tab, spfx->flags);
  937.                 break;
  938.             case 2:
  939.                 fprintf(out, "%sS2FX FLAGS=%u ", tab, spfx->flags);
  940.                 break;
  941.             case 3:
  942.                 fprintf(out, "%sS3FX FLAGS=%u ", tab, spfx->flags);
  943.                 break;
  944.             case 4:
  945.                 fprintf(out, "%sS4FX FLAGS=%u ", tab, spfx->flags);
  946.         }
  947.         fprintf(out, "START=%u ", spfx->start);
  948.         fprintf(out, "STOP=%u ", spfx->stop);
  949.         fprintf(out, "NAME=\"%s\" ", spfx->effect);
  950.         fprintf(out, "DATA=\"%s\"\n", spfx->effect_data); 
  951.     }
  952. }
  953.